<?php
namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;

class CollectionExport implements FromCollection, ShouldAutoSize, WithHeadings {

    private $collection_data;
    private $headings;

    public function __construct($collection_data, $headings = [])
    {
        $this->collection_data = $collection_data;
        $this->headings = $headings;
    }

    public function collection()
    {
        return $this->collection_data;
    }

    public function columnFormats(): array
    {
        return [
            'goods_amount' => NumberFormat::FORMAT_NUMBER_00,
            'discounts_amount' => NumberFormat::FORMAT_NUMBER_00,
            'order_amount' => NumberFormat::FORMAT_NUMBER_00,
            'payed' => NumberFormat::FORMAT_NUMBER_00,
            'coins_pay' => NumberFormat::FORMAT_NUMBER_00,
        ];
    }

    public function headings(): array
    {
        return $this->headings;
    }
}
